//
//  CarManagerView.m
//  Runone
//
//  Created by runone01 on 16/10/25.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "CarManagerView.h"
#import "Masonry.h"
#import "AppConstants.h"

@implementation CarManagerView

-(instancetype)initWithFrame:(CGRect)frame {
    self=[super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self configUI];
        [self layoutUI];
        
    }
    return self;
}

- (void) configUI {
    
    _iconImg         = [[UIImageView alloc] init];
    _iconImg.image   = [UIImage imageNamed:@"guangle_G4W3.png"];
    [self addSubview:_iconImg];
    
    _detailL              = [[UILabel alloc] init];
    _detailL.font         = KTitleTextFont;
    _detailL.textColor    = kROLightFrayTextColor;
    _detailL.text         = @"详情";
    [self addSubview:_detailL];
    
    _narrowImg       = [[UIImageView alloc] init];
    _narrowImg.image = [UIImage imageNamed:@"right_arrow"];
    [self addSubview:_narrowImg];
    
    _VehicleType              = [[UILabel alloc] init];
    _VehicleType.font         = kShowContentTextFont;
    _VehicleType.textColor    = kROLightFrayTextColor;
    [self addSubview:_VehicleType];
    
    _OD_RateL                  = [[UILabel alloc] init];
    _OD_RateL.font             = kShowContentTextFont
    _OD_RateL.textColor        = kROLightFrayTextColor;
    [self addSubview:_OD_RateL];
    
    _VehicleNo                 =  [[UILabel alloc] init];
    _VehicleNo.font            = kShowContentTextFont;
    _VehicleNo.textColor       = kROLightFrayTextColor;
    [self addSubview:_VehicleNo];
    
    _DirectionL                 = [[UILabel alloc] init];
    _DirectionL.font            = kShowContentTextFont;
    _DirectionL.textColor       = kROLightFrayTextColor;
    [self addSubview:_DirectionL];
}

//布局UI
- (void) layoutUI {
    __weak __typeof(self)weakSelf = self;
    
    [_iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(10);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(40);
    }];
    
    [_VehicleNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(5);
        make.left.mas_equalTo(weakSelf.iconImg.mas_right).with.offset(5);
        make.height.mas_equalTo(20);
        make.width.mas_greaterThanOrEqualTo(100);
    }];
    
    [_VehicleType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.VehicleNo.mas_bottom).with.offset(5);
        make.left.mas_equalTo(weakSelf.iconImg.mas_right).with.offset(5);
        make.height.mas_equalTo(20);
        make.width.mas_greaterThanOrEqualTo(100);
    }];
    
    
    [_narrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.right.mas_equalTo(weakSelf.mas_right).with.offset(-10);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);
    }];
    
    [_detailL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.right.mas_equalTo(weakSelf.narrowImg.mas_left).with.offset(10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(40);
    }];
    
    [_OD_RateL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(5);
        make.left.mas_equalTo(weakSelf.mas_centerX);
        make.height.mas_equalTo(20);
        make.width.mas_greaterThanOrEqualTo(100);
    }];
    
    [_DirectionL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.OD_RateL.mas_bottom).with.offset(5);
        make.left.mas_equalTo(weakSelf.OD_RateL.mas_left);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(80);
    }];
}
#pragma mark - 车辆管理
- (void)setModel:(CarManagerModel *)model {
    _model = model;
}
- (void)setCarNum:(NSString *)carNO carType:(NSInteger)carType vehicleSpeed:(NSString *)carSpeed carDirection:(NSString *)carDirection {
    if (carType == 1) {
        _VehicleType.text=[NSString stringWithFormat:@"路政车辆"];
    }
    if (carType == 2) {
        _VehicleType.text=[NSString stringWithFormat:@"救援车辆"];
    }
    if (carType == 3) {
        _VehicleType.text=[NSString stringWithFormat:@"养护车辆"];
    }
    if (carType == 4) {
        _VehicleType.text=[NSString stringWithFormat:@"消防车辆"];
    }
    if (carType == 5) {
        _VehicleType.text=[NSString stringWithFormat:@"行政车辆"];
    }
    
    if ([carDirection isEqualToString:@"1"]) {
        
    }else {
        _DirectionL.text  = @"往湖南方向";
    }
    
    _VehicleNo.text   = carNO;
    _OD_RateL.text    = [NSString stringWithFormat:@"车速:%@km/h",carSpeed];
}
#pragma mark - 两客一危
- (void)setDynamicModel:(AllLastestVehicleDynamic *)dynamicModel {
    _dynamicModel = dynamicModel;
}
- (void)setDynamicNum:(NSString *)dynamicNO carType:(NSString *)dynamicType dynamicSpeed:(NSInteger)dynamicSpeed dynamicDirection:(NSString *)dynamicDirection{
    
    _narrowImg.hidden = YES; //屏蔽该功能
    _detailL.hidden   = YES; //屏蔽该功能
    
    if ([dynamicType integerValue] == 30 ||[dynamicType integerValue] == 31|| [dynamicType integerValue] == 32) {
        _VehicleType.text      = @"危化品车";
    } else {
        _VehicleType.text      = @"营运客车";
    }
    
    
    if ([dynamicDirection integerValue] == 1) {
        _DirectionL.text  = @"往广州方向";
    }else {
        _DirectionL.text  = @"往湖南方向";
    }
    
    
    _VehicleNo.text   = dynamicNO;
    _OD_RateL.text    = [NSString stringWithFormat:@"车速:%ldkm/h",(long)dynamicSpeed];
}

#pragma mark - 高速全览-当前事件
-(void)setCurrentModel:(CurrentEvent *)currentModel {
    _currentModel = currentModel;
}
- (void)setCurrentType:(NSInteger)IncidentParentType BeginPile:(NSString *)beginPile BeginPileDistance:(NSString *)beginDistacne EndPile:(NSString *)endPile EndPileDistance:(NSString *)endPileDistance RoadUID:(NSString *)RoadUID{
    if (IncidentParentType == 3) {
        _VehicleNo.text = @"施工事件";
        _iconImg.image  = [UIImage imageNamed:@"event_construct_main_icon"];
        //广乐特殊的要求，只能写死
        if ([RoadUID isEqualToString:@"8dd13d88-cb02-4471-876b-1dfe39419ee6"]) {
             _VehicleType.text = [NSString stringWithFormat:@"%@+%@至%@+%@",beginPile, beginDistacne, endPile, endPileDistance];
        } else {
            NSString *LStr       = @"L";
            NSString *beginLKStr = [LStr stringByAppendingString:beginPile];
            NSString *endLKStr   = [LStr stringByAppendingString:endPile];
            _VehicleType.text = [NSString stringWithFormat:@"%@+%@至%@+%@",beginLKStr, beginDistacne, endLKStr, endPileDistance];
        }
    }else {
        _VehicleNo.text = @"事故事件";
        _iconImg.image  = [UIImage imageNamed:@"event_accident_icon"];
        
        //广乐特殊的要求，只能写死
        if ([RoadUID isEqualToString:@"8dd13d88-cb02-4471-876b-1dfe39419ee6"]) {
            _VehicleType.text = [NSString stringWithFormat:@"%@+%@",beginPile, beginDistacne];
        } else {
            NSString *LStr       = @"L";
            NSString *beginLKStr = [LStr stringByAppendingString:beginPile];
            _VehicleType.text = [NSString stringWithFormat:@"%@+%@",beginLKStr, beginDistacne];
        }

    }
}

- (void) dimiss {
    [self removeFromSuperview];
}

@end
